package cn.kgc.util;

import cn.kgc.dao.BaseDao;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;


public class DataBaseUtil_jndi {


    /**
     * 获取链接的方法
     * @return
     */
    public static Connection getConnect(){
        String JNDINAME = "java:comp/env/jdbc/news" ;
        Connection conn = null ;
        try
        {
            // 初始化查找命名空间
            Context ctx = new InitialContext() ;
            // 找到DataSource
            DataSource ds = (DataSource)ctx.lookup(JNDINAME) ;
            conn = ds.getConnection() ;
        }
        catch(Exception e)
        {
            System.out.println(e) ;
        }
        return conn;
    }


}
